<?php
session_start();
include('GMApi/GMApi.php');

@include_once("account.php");
$email = (defined("GM_EMAIL") ? GM_EMAIL : "your gmail account");
$password = (defined("GM_PASSWORD") ? GM_PASSWORD : "your gmail password");
$mac_address = (defined("GM_MACADDRESS") ? GM_MACADDRESS : "your mac address"); // xx-xx-xx-xx-xx

$api = new GMApi();
$api->setDebug(true);
$api->enableRestore(true);
$api->enableMACAddressCheck(true);
$api->enableSessionFile(true);

if(!$api->login($email, $password, $mac_address)) {
	die("login fail");
}

PrintOutput("login success. This login is using ".$api->getLoginResultType());

//$res = $api->upload("h.mp3");
//$res = $api->upload(array("h.mp3","x.mp3"));
$res = demo_detail_upload(array("h.mp3","x.mp3"));

if($res == false) {
	die("unable upload");
}

foreach($res as $key=>$value) {
	$songid = $value;
	PrintOutput("getting ".$songid);
	$stream_url = $api->get_stream_url($songid);
	if($stream_url == false) {
		PrintOutput("unable get stream url");
	} else {
		PrintOutput("stream url: ".$stream_url);
	}
	
	$download_info = $api->get_download_info($songid);
	if($download_info == false) {
		PrintOutput("unable get download url");
	} else {
		PrintOutput("download url: ".$download_info['url']);
	}
}

function PrintOutput($message) {
	echo $message."<br/><br/>";
	GMAPIUtils::flushOutput();
}

function demo_detail_upload($paths) {
	global $api;
	$infos = array();
	foreach($paths as $path) {
		$data = array(
			"filepath"=>$path,
			"track"=>array(
				//"creation"=>intval(date("U")),
				//"lastPlayed"=>intval(date("U")),
				"title"=>"my title",
				"artist"=>"my artist",
				"composer"=>"my composer",
				"album"=>"my album",
				"albumArtist"=>"my albumArtist",
				"year"=>2012,
				"comment"=>"my comment",
				"track"=>1,
				"genre"=>"my genre",
				"duration"=>60000, // 60 seconds, use getID3 library
				"beatsPerMinute"=>1,
				"playCount"=>0,
				"totalTracks"=>1,
				"disc"=>1,
				"totalDiscs"=>1,
				"rating"=>0,
				//"fileSize" let api do it
				//"u13"=>0,
				//"u14"=>0,
				"bitrate"=>192,
				//"u15"=>"",
				//"u16"=>0
			)
		);
		$infos[] = $data;
	}
	
	$res = $api->upload($infos);
	return $res;
}


die("done");

?>